package com.ruoyi.web.controller.front;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.front.domain.LawyerTeam;
import com.ruoyi.front.service.ILawyerTeamService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 律师Controller
 * 
 * @author ruoyi
 * @date 2020-11-07
 */
@Controller
@RequestMapping("/front/team")
public class LawyerTeamController extends BaseController
{
    private String prefix = "front/team";

    @Autowired
    private ILawyerTeamService lawyerTeamService;

    @RequiresPermissions("front:team:view")
    @GetMapping()
    public String team()
    {
        return prefix + "/team";
    }

    /**
     * 查询律师列表
     */
    @RequiresPermissions("front:team:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LawyerTeam lawyerTeam)
    {
        startPage();
        List<LawyerTeam> list = lawyerTeamService.selectLawyerTeamList(lawyerTeam);
        return getDataTable(list);
    }

    /**
     * 导出律师列表
     */
    @RequiresPermissions("front:team:export")
    @Log(title = "律师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LawyerTeam lawyerTeam)
    {
        List<LawyerTeam> list = lawyerTeamService.selectLawyerTeamList(lawyerTeam);
        ExcelUtil<LawyerTeam> util = new ExcelUtil<LawyerTeam>(LawyerTeam.class);
        return util.exportExcel(list, "team");
    }

    /**
     * 新增律师
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存律师
     */
    @RequiresPermissions("front:team:add")
    @Log(title = "律师", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LawyerTeam lawyerTeam)
    {
        return toAjax(lawyerTeamService.insertLawyerTeam(lawyerTeam));
    }

    /**
     * 修改律师
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LawyerTeam lawyerTeam = lawyerTeamService.selectLawyerTeamById(id);
        mmap.put("lawyerTeam", lawyerTeam);
        return prefix + "/edit";
    }

    /**
     * 修改保存律师
     */
    @RequiresPermissions("front:team:edit")
    @Log(title = "律师", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LawyerTeam lawyerTeam)
    {
        return toAjax(lawyerTeamService.updateLawyerTeam(lawyerTeam));
    }

    /**
     * 删除律师
     */
    @RequiresPermissions("front:team:remove")
    @Log(title = "律师", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lawyerTeamService.deleteLawyerTeamByIds(ids));
    }
}
